package day12.homework.project1;

import java.lang.reflect.Field;
import java.lang.reflect.Method;

public class test {

    public static void main(String[] args) throws Exception {

        Class<Person> p = Person.class;
        Object obj = p.newInstance();

        // 通过反射调用setName方法赋值
        Method d = p.getMethod("setName", String.class);
        d.invoke(obj, "小明");

        // 通过暴力反射直接给age赋值
        Field age = p.getDeclaredField("age");
        age.setAccessible(true);
        age.set(obj, 15);

        System.out.println(obj);

    }
}
